package com.benin.sms.network

import androidx.lifecycle.ViewModel
import com.benin.sms.model.ToBase
import com.benin.sms.model.ToSavePhoneNumberStateTo
import kotlinx.coroutines.Dispatchers

object RepoUserProcess : RepoBase() {

    fun getNextPhoneNumber(caller: ViewModel?, toBase: ToBase) =
        fire(Dispatchers.IO, caller, toBase.showLoading) {
            val response = NetUserProcessImp.getNextPhoneNumber(toBase)
            if (response.code.equals("0000", true)) {
                val obj = response.obj
                Result.success(obj)
            } else {
                Result.failure(NetworkException(response.code, response.msg))
            }
        }

    fun savePhoneNumberState(
        caller: ViewModel?,
        toSavePhoneNumberStateTo: ToSavePhoneNumberStateTo
    ) =
        fire(Dispatchers.IO, caller, toSavePhoneNumberStateTo.showLoading) {
            val response = NetUserProcessImp.savePhoneNumberState(toSavePhoneNumberStateTo)
            if (response.code.equals("0000", true)) {
                val obj = response.obj
                Result.success(obj)
            } else {
                Result.failure(NetworkException(response.code, response.msg))
            }
        }
}